package com.tarena.dang.utils;

import java.io.IOException;
import java.util.UUID;

public class VerifyCodeUtils {
	public static String getVerifyCode(Integer id) {
		UUID uuid = UUID.randomUUID();
		String uuidStr = uuid.toString() + "-" + id;
		String es = EncryptUtil.Base64Encrypt(uuidStr.getBytes());
		return es;
	}
	
	public static String getVerifyCode(Integer id,String uuid) {
		String uuidStr = uuid.toString() + "-" + id;
		String es = EncryptUtil.Base64Encrypt(uuidStr.getBytes());
		return es;
	}

	public static String getUUID(String verifyCode) {
		byte[] bys;
		try {
			bys = EncryptUtil.Base64Decrypt(verifyCode);
			String s = new String(bys);
			int index = s.lastIndexOf("-");
			return s.substring(0, index);
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}

	public static String getUserID(String verifyCode) {
		byte[] bys;
		try {
			bys = EncryptUtil.Base64Decrypt(verifyCode);
			String s = new String(bys);
			int index = s.lastIndexOf("-") + 1;
			return s.substring(index);
		} catch (IOException e) {
			e.printStackTrace();
			return "";
		}
	}
}
